package com.sgmw.sales.tool.kong.sign.headers;

import com.sgmw.sales.tool.kong.sign.utils.SHA256Util;

/**
 * 对请求体进行数字摘要
 * @author hujunwei
 * @d2019年3月14日
 */
public class SignHeaderDigest implements RequestHeader{
	private String content;
	private String signString;
	
	public SignHeaderDigest(String content) {
		this.content = content;
		String digestBody = "";
		try {
			sun.misc.BASE64Encoder base64 = new sun.misc.BASE64Encoder();
			digestBody = base64.encode(SHA256Util.getSHA256Bytes(this.content));
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		this.signString = "SHA-256=" + digestBody;
	}

//	@Override
//	public String getSignString() {
//		String digestBody = "";
//		try {
//			digestBody = new String(Base64.getEncoder().encode(SHA256Util.getSHA256Bytes(content)), "US-ASCII");
//		} catch (UnsupportedEncodingException e1) {
//			e1.printStackTrace();
//		}
//		String signString = getName() + ":" + " SHA-256=" + digestBody;
//		return signString;
//	}
	
	@Override
	public String getName() {
		return "Digest";
	}

	@Override
	public String getValue() {
		return signString;
	}

	@Override
	public String toString() {
		return  getName()+": "+signString;
	}
}
